package com.ndkj.rpcserver.loadbalance;

import com.ndkj.rpcserver.common.dto.URL;

import java.util.List;
import java.util.Random;

/**
 * 负载均衡的简易实现
 * 想要了解更多负载均衡算法可以参考https://cloud.tencent.com/developer/article/1803735
 */
public class LoadBalanceRule {

    /**
     * 随机
     */
    public static URL randomRule(List<URL> hosts) {
        int i = new Random().nextInt(hosts.size());
        return hosts.get(i);
    }

    /**
     * 简单轮询
     */
    @Deprecated
    public static URL RoundRobinRule(List<URL> hosts) {
        // ...
        return null;
    }

    /**
     * 加权轮询
     */
    @Deprecated
    public static URL WeightedRoundRobinRule(List<URL> hosts) {
        // ...
        return null;
    }

    // ...
}
